﻿@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
@using Volo.CmsKit.Admin.Web.Pages
@using Volo.CmsKit.Localization
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents;
@inject IHtmlLocalizer<CmsKitResource> L

@model AddWidgetModal;
@{
    Layout = null;
}

@section scripts {
    <abp-script src="/Pages/CmsKit/Contents/addWidgetModal.js" />
}
@{
    bool isDefinedWidget = Model.Widgets.Count() > 1;
}
<abp-modal size="Large" id="addWidgetModal">
    <abp-modal-header title="@L["AddWidget"].Value"></abp-modal-header>
    <abp-modal-body>
        <div class="container">
            @if (isDefinedWidget)
            {
                <abp-select asp-for="ViewModel.Widget" />

                foreach (var item in Model.ViewModel.Details)
                {
                    if (item.EditorComponentName is not null)
                    {
                        <div hidden id="editor-@item.Name">
                            <form data-check-form-on-close="false">
                                @await Component.InvokeAsync(@item.EditorComponentName)
                            </form>
                        </div>
                    }
                }
            }
            else
            {
                <p>@L["PleaseConfigureWidgets"].Value</p>
            }
        </div>
    </abp-modal-body>
    <abp-modal-footer>
        @if (isDefinedWidget)
        {
            <button class="btn btn-primary float-end save-changes" type="submit">@L["Add"]</button>
        }
    </abp-modal-footer>
</abp-modal>
